@echo off
setlocal enabledelayedexpansion

:: 执行adb命令并获取输出
for /f "delims=" %%a in ('adb shell dumpsys window ^| findstr mCurrentFocus') do (
    set "line=%%a"
    :: 检查行中是否包含"com."
    echo !line! | findstr /C:"com." >nul
    if not errorlevel 1 (
        :: 提取包名
        for /f "tokens=4 delims={} " %%b in ("!line!") do (
            set "package_name=%%b"
            for /f "tokens=1 delims=/" %%c in ("!package_name!") do (
                set "final_package=%%c"
                echo package_name: !final_package!
                goto :end
            )
        )
    )
)

:: 如果没有找到包名
echo package_name: None
:end
endlocal

pause